﻿using System;
using System.Net;

namespace FBGraph.Async
{
    /// <summary>Defines a contract for a queued asynchronous Graph API request.</summary>
    public interface IFBGraphAsyncRequest
    {
        /// <summary>Occurs when an exception is thrown while executing the <see cref="InnerRequest" />.</summary>
        event FBGraphAsyncErrorHandler Error;

        /// <summary>Gets a reference to the <see cref="HttpWebRequest" /> that is executed.</summary>
        HttpWebRequest InnerRequest { get; }

        /// <summary>Gets or sets the number of attempts that have been made at executing the request.</summary>
        Int32 Attempts { get; set; }

        /// <summary>Gets the type of data object that the response of the request will be deserialized to.</summary>
        Type ReturnType { get; }

        /// <summary>Gets a reference to the <see cref="IFBGraphResult" /> object that was returned from the original method call.</summary>
        IFBGraphResult Result { get; set; }

        /// <summary>Gets or sets a value representing whether the request has been completed.</summary>
        Boolean IsCompleted { get; set; }

        /// <summary>Gets or sets an <see cref="Exception" /> that may have occurred during the course of the request.</summary>
        Exception Exception { get; set; }

        /// <summary>Gets a reference to a <see cref="IFBGraphAsyncRequest" /> that this instance depends on. If this property is not null,
        /// the dependent request will not be executed until the dependency request is completed.</summary>
        IFBGraphAsyncRequest Dependency { get; }

        /// <summary>Fires the <see cref="Error" /> event.</summary>
        /// <param name="e">An instance of <see cref="FBGraphAsyncErrorEventArgs" /> containing information about the event.</param>
        void OnError(FBGraphAsyncErrorEventArgs e);
    }
}